package billings.classtasks.classes;

import billings.classtasks.ClassTasksActivity;
import billings.classtasks.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class EditClass extends Activity implements OnClickListener {

	private EditText cNumber;
	private EditText cMajor;
	private EditText cProf;
	protected long classId;
	
	private Button update;
	private Button cancel;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.create_class);
        
        Bundle extras = getIntent().getExtras();
        classId = extras.getLong("classId");
        
        cNumber = (EditText)findViewById(R.id.courseNumber);
        cMajor = (EditText)findViewById(R.id.courseMajor);
        cProf = (EditText)findViewById(R.id.courseProf);
        
        cNumber.setText(extras.getString("courseNumber"));
        cMajor.setText(extras.getString("courseMajor"));
        cProf.setText(extras.getString("courseProfessor"));
        
        update = (Button)findViewById(R.id.createClass);
        cancel = (Button)findViewById(R.id.cancelClass);
        update.setText("Update");
        
        update.setOnClickListener(this);
        cancel.setOnClickListener(this);
	}
	
	public void onClick(View v) {
		Intent i;
		switch(v.getId()){
		case R.id.createClass:
			i = new Intent(this, ClassTasksActivity.class);
			
			//package class values
			Bundle classVals = new Bundle();
			classVals.putLong("classId", EditClass.this.classId);
			classVals.putString("courseNumber", cNumber.getText().toString());
			classVals.putString("courseMajor", cMajor.getText().toString());
			classVals.putString("courseProfessor", cProf.getText().toString());
			i.putExtra("classVals", classVals);
			i.putExtra("action", "update");
			startActivity(i);
			break;
		case R.id.cancelClass:
			i = new Intent(this, ClassTasksActivity.class);
			startActivity(i);
			break;
		}
	}

}
